package sz.szsmk.citizencard.ui.dzsmkavtivity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.dzbean.res.CitizenCard;
import sz.szsmk.citizencard.mvp.BasePresenter;
import sz.szsmk.citizencard.mvp.MyCitizenCardMvpView;
import sz.szsmk.citizencard.mvp.dzsmkpresenter.MyCitizenCardPresenter;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.widget.CitzenCardTextView;

/**
 * Created by chensf on 17/10/1.
 */

public class MyCitizenCardActivity extends AppBaseActivity implements MyCitizenCardMvpView {

    @Inject
    MyCitizenCardPresenter mMyCitizenCardPresenter;

    RecyclerView rv_qr_my_citizen_card;
    private BaseQuickAdapter mAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getComponent().inject(this);
        setContentView(R.layout.qr_activity_my_citizen_card);

        rv_qr_my_citizen_card = findViewById(R.id.rv_qr_my_citizen_card);

        ImmersionBar.with(this)
                .fitsSystemWindows(true)
                .statusBarDarkFont(true, 0f)
                .statusBarColor(R.color.white).init();
        rv_qr_my_citizen_card.setLayoutManager(new LinearLayoutManager(MyCitizenCardActivity.this));
        mAdapter = new BaseQuickAdapter<CitizenCard, BaseViewHolder>(R.layout.qr_item_my_citizen_card, new ArrayList<CitizenCard>()) {

            @Override
            protected void convert(BaseViewHolder helper, CitizenCard item) {
                CitzenCardTextView ctv = helper.getView(R.id.tv_qr_citizen_card_number);
                ctv.setText(item.getCardNumber());
//                helper.setText(R.id.tv_qr_citizen_card_number,item.getCardNumber());
            }
        };
        rv_qr_my_citizen_card.setAdapter(mAdapter);
        mMyCitizenCardPresenter.gainMyCitizenCard();
    }

    @Override
    protected BasePresenter[] initPresenters() {
        return new BasePresenter[]{mMyCitizenCardPresenter};
    }

    @Override
    protected CharSequence getTopTitle() {
        return getString(R.string.qr_my_citizen_card);
    }

    @Override
    public void gainMyCitizenCard(List<CitizenCard> citizenCards) {
        L.e(Constant.MTAG, "------------");
        mAdapter.setNewData(citizenCards);
        mAdapter.notifyDataSetChanged();
    }
}
